﻿#pragma once
#include "AsEnvironmentVariables.h"
#include "AsEnvironmentGlobal.h"

__AS_JY(Update 2023.1.8)
class ADF_EXPORT AsEnvironment : 
	public AsEnvironmentVariables, 
	public AsEnvironmentGlobal 
{
public:
	AsEnvironment(int argc, char* argv[]);
	virtual ~AsEnvironment();

public:
	int exec();
	void initialize();
	void specifyMainWindow(QWidget* main);

protected:
	virtual void construct();

public:
	QWidget* wMain();

public:
	QString getRecentPath();
	void setRecentPath(const QString& value);
	QString getRecentDirectory();
	void setRecentDirectory(const QString& value);
	QString getDataPath();
	void setDataPath(const QString& value);
	QString getOutputPath();
	void setOutputPath(const QString& value);

	enum ProgramMode { /*Default:*/ModeRelease = 0x01, ModeDebugConsole = 0x02 };
	int getProgramMode();
	void setProgramMode(int mode);

public:
	QString getLoadFilename(const QString& caption = "加载文件", const QString& filter = QString());
	QStringList getLoadFilenames(const QString& caption = "加载多个文件", const QString& filter = QString());
	QString getSaveFilename(const QString& filename, const QString& caption = "保存文件", const QString& filter = QString());

	void infomation(const QString& info);
	void warning(const QString& info);
	void critical(const QString& info);
	bool question(const QString& info);

public:
	QString getExeDirectory();

public:
	template <typename _Slot>
	void guiCall(_Slot slot) {
		if (w_main == nullptr) throw AsQException(AsQException::CodeEnvironment_NoGuiSpecified, "使用guiCall时，没有提前指定GUI对象指针");
		AsCall::execute(w_main, slot);
	}
	template <typename _Slot>
	void guiBlockCall(_Slot slot) {
		if (w_main == nullptr) throw AsQException(AsQException::CodeEnvironment_NoGuiSpecified, "使用guiCall时，没有提前指定GUI对象指针");
		AsCall::execute(w_main, slot, Qt::ConnectionType::BlockingQueuedConnection);
	}

private:
	QApplication app;
	QWidget* w_main;

public:
	static int		ARGC;
	static char**	ARGV;
	static constexpr const char* RECENT_PATH = "recent_path";
	static constexpr const char* RECENT_DIR = "recent_directory";
	static constexpr const char* DATA_PATH = "data_path";
	static constexpr const char* OUTPUT_PATH = "output_path";
	static constexpr const char* PROGRAM_MODE = "program_mode";

};

namespace As {

	ADF_EXPORT AsEnvironment& env();

	ADF_EXPORT bool createConta(QString filename, const AsObject& object, bool isCover = false);
};

#define asEnv As::env()